package cn.am.service.impl;

import cn.am.mapper.PlanMapper;
import cn.am.pojo.PlanVO;
import cn.am.service.PlanService;
import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author : ArturiaMu KMUST-Stu
 * @Date : 2022/8/14 12:46
 * @Params : @param null
 * @Exception :
 * @Return :
 * @Description ：
 */
@Service
public class PlanServiceImpl implements PlanService {
    @Autowired
    private PlanMapper planMapper;

    @Override
    public ResponseResult<PlanVO> save(PlanVO planVO) {
        int code = planMapper.save(planVO);
        if (code == 1) {
            return ResponseResult.success(planVO);
        } else {
            return ResponseResult.fail(planVO);
        }
    }

    @Override
    public ResponseResult<Boolean> del(Long id) {
        int code = planMapper.del(id);
        if (code == 1) {
            return ResponseResult.success(true);
        } else {
            return ResponseResult.fail(false);
        }
    }

    @Override
    public ResponseResult getAvailablePlan(Date date) {
        List<PlanVO> availablePlan = planMapper.getAvailablePlan(date);
        return ResponseResult.success(availablePlan);
    }

    @Override
    public ResponseResult<List<PlanVO>> getByUserId(Long uid) {
        List<PlanVO> byUserId = planMapper.getByUserId(uid);
        return ResponseResult.success(byUserId);
    }

    @Override
    public ResponseResult<PlanVO> getById(Long id) {
        return ResponseResult.success(planMapper.getById(id));
    }
}
